// components/comment-popup/index.ts
import { queryShortVideoComment } from "../../api/index"
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    CamID: {
      type: String,
      value: ''
    },
    isShowComment: {
      type: Boolean,
      value: false,
      observer: "setAnimation"
    },
    currentId: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    commentAnimate: "",
    commentlist: [],
    addmsg: {} as any,
    tabContentHeight: "",
    commentPageOption: {
      PageIndex: 1,
      PageSize: 20
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    setReplyTarget(event) {
      const pages = getCurrentPages();
      const currentPage = pages[pages.length - 1]
      currentPage.selectComponent("#send-message").setReplyTarget(event.detail)
    },
    queryComment() {
      const params = {
        PageOptions: this.data.commentPageOption,
        ShortVideoId: this.properties.currentId
      }
      queryShortVideoComment(params).then(res => {
        if (!res.Data) return
        let list = res.Data.map(element => {
          element["isShowChildren"] = false
          return element
        });
        this.setData({
          commentlist: list
        })
      })
    },
    setAnimation(val) {
      const height = val ? "60vh" : "0"
      const animationC = wx.createAnimation({ duration: 250 });
      animationC.height(height).step()
      this.setData({ commentAnimate: animationC })
      this.queryComment()
    },
    setAddMsg(detail) {
      this.setData({
        addmsg: detail
      })
    }
  }
})
